package cn.edu.scau.cmi.liuan.factoryMode;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class test extends Application {
	String[] i = new String[4];
	ObservableList<String> items = null;
	Factory isrF = new Factory();
	Insurance isr = null;
	
	Pane p = new Pane();
	ImageView img = new ImageView("file:src/cn/edu/scau/cmi/liuan/factoryMode/resource/1.jpg");
	Text t1 = new Text();
	Text t2 = new Text();
	ComboBox<String> cbo = new ComboBox<>();
	Button bt = new Button();
	TextArea ta = new TextArea();
	
	public static void main(String args[]) {

		launch(args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		
		i[0] = "驾驶员受伤";
		i[1] = "汽车损坏";
		i[2] = "人员伤亡";
		i[3] = "多种事故";
		items = FXCollections.observableArrayList(i);
		
		
		img.setFitHeight(200);
		img.setFitWidth(200);
		img.setLayoutX(0);
		img.setLayoutY(0);
		
		t1.setText("姓名:刘安  \t\t学号：201627010415");
		t1.setLayoutX(250);
		t1.setLayoutY(50);
		
		t2.setText("请选择保险");
		t2.setLayoutX(250);
		t2.setLayoutY(150);
		
		
		cbo.getItems().addAll(items);
		cbo.setStyle("-fx-color:gray");
		cbo.setLayoutX(420);
		cbo.setLayoutY(135);
		
		bt.setText("显示保险信息");
		bt.setLayoutX(300);
		bt.setLayoutY(200);
		bt.setOnAction(e -> event_bt());
		
		ta.setLayoutX(50);
		ta.setLayoutY(250);
		
		p.setPrefSize(500, 500);
		p.getChildren().addAll(img,t1,t2,cbo,bt,ta);
		Scene scene = new Scene(p,800,600);
		primaryStage.setScene(scene);
		primaryStage.setTitle("简单工厂模式");
		primaryStage.show();
	}
	
	public void event_bt() {
		if(cbo.getValue()!=null) {
			isr = isrF.GetInsurance((int)items.indexOf(cbo.getValue()));
			ta.setText(isr.toInfo());
		}
	}
}
